package com.letv.ads.util;

import java.util.HashMap;

import android.content.Context;

import com.letv.adlib.model.utils.SoMapperKey;
import com.letv.adlib.sdk.types.ArkAdReqParam;
import com.letv.adlib.sdk.utils.IPlayerStatusDelegate;
import com.letv.ads.AdsManager;

/**
 * 广告请求配置类
 */
public class ClientInfoUtil {

    /**
     * 生成简单的客户端信息。一般的界面中的广告，不需要正片相关信息
     *
     * @return
     */
    public static ArkAdReqParam getClientInfo(Context context) {

        ArkAdReqParam reqParam = new ArkAdReqParam();
        reqParam.context = context.getApplicationContext();// SDK需要这个，以实现更丰富的功能
        reqParam.dynamicParams = new HashMap<String, String>();
        reqParam.isDisableAd = !AdsManager.getInstance().isShowAd();// 是否禁用广告。这个移动端是有个开关来管理广告的，暂时我们也用这个开关的值。同样不播广告，我也得上报。
        reqParam.isDisableOfflineAd = !AdsManager.getInstance().isShowOfflineAd();// 是否禁用离线广告。这个移动端是有个开关来管理广告的，暂时我们也用这个开关的值。同样不播广告，我也得上报。
        reqParam.isVIP = AdsManager.getInstance().isVip();// 是否为VIP。一般情况下，我们知道是VIP，就不会请求广告系统了，但需要发上报。

        return reqParam;
    }

    /**
     * 开机广告
     *
     * @return
     */
    public static ArkAdReqParam getBeginInfo(Context context) {
        ArkAdReqParam vInfo = getClientInfo(context);
        vInfo.adZoneType = ArkAdReqParam.LetvAdZoneType.SPLASH_SCREEN;// 开机启动图
        return vInfo;
    }

    /**
     * 播放器内广告，需要与正片相关的信息
     *
     * @return
     */
    public static ArkAdReqParam getFocusInfo(Context context) {
        ArkAdReqParam vInfo = getClientInfo(context);
        vInfo.adZoneType = ArkAdReqParam.LetvAdZoneType.FOCUS;// 焦点图
        return vInfo;
    }

    /**
     * 播放器内广告，需要与正片相关的信息
     *
     * @return
     */
    public static ArkAdReqParam getBannerInfo(Context context, String cid, String pid) {
        ArkAdReqParam reqParam = getClientInfo(context);
        if (reqParam.dynamicParams == null){
            reqParam.dynamicParams = new HashMap<String, String>();
        }
        reqParam.dynamicParams.put("cid",cid);
        reqParam.dynamicParams.put("pid",pid);

        return reqParam;
    }

    /**
     * 点播播放器内广告，需要与正片相关的信息
     *
     * @return
     */
    public static ArkAdReqParam getVideoPlayerInfo(Context context, String cid, String pid, String vid, String mmsid, String uuid, String uid, String vlen, String py, String ty, IPlayerStatusDelegate iPlayerStatusDelegate) {
        ArkAdReqParam reqParam = getClientInfo(context);
        if (reqParam.dynamicParams == null){
            reqParam.dynamicParams = new HashMap<String, String>();
        }
        reqParam.dynamicParams.put(SoMapperKey.CID,cid);
        reqParam.dynamicParams.put(SoMapperKey.PID,pid);
        reqParam.dynamicParams.put(SoMapperKey.VID,vid);
        reqParam.dynamicParams.put(SoMapperKey.MMSID,mmsid);
        reqParam.dynamicParams.put(SoMapperKey.UUID,uuid);
        reqParam.dynamicParams.put(SoMapperKey.UID,uid);
        reqParam.dynamicParams.put(SoMapperKey.VLEN,vlen);
        reqParam.dynamicParams.put(SoMapperKey.PY,py);
        reqParam.dynamicParams.put(SoMapperKey.TY,ty);
        reqParam.dynamicParams.put(SoMapperKey.HTIME,AdsManager.getInstance().getIsQRCodeVideoTime() + "");
        return reqParam;
    }

    /**
     * 点播播放器内广告，需要与正片相关的信息  带有影片付费信息
     *
     * @return
     */
    public static ArkAdReqParam getVideoPlayerInfo(Context context, String cid, String pid, String vid, String mmsid, String uuid, String uid, String vlen, String py, String ty, IPlayerStatusDelegate iPlayerStatusDelegate, boolean isVipVideo) {
        ArkAdReqParam reqParam = getClientInfo(context);
        if (reqParam.dynamicParams == null){
            reqParam.dynamicParams = new HashMap<String, String>();
        }
        reqParam.adReqType = ArkAdReqParam.AdReqType.REQ_Vod;
        reqParam.iPlayerStatusDelegate = iPlayerStatusDelegate;
        reqParam.isTryLook = isVipVideo;
        reqParam.dynamicParams.put(SoMapperKey.CID,cid);
        reqParam.dynamicParams.put(SoMapperKey.PID,pid);
        reqParam.dynamicParams.put(SoMapperKey.VID,vid);
        reqParam.dynamicParams.put(SoMapperKey.MMSID,mmsid);
        reqParam.dynamicParams.put(SoMapperKey.UUID,uuid);
        reqParam.dynamicParams.put(SoMapperKey.UID,uid);
        reqParam.dynamicParams.put(SoMapperKey.VLEN,vlen);
        reqParam.dynamicParams.put(SoMapperKey.PY,py);
        reqParam.dynamicParams.put(SoMapperKey.TY,ty);
        reqParam.dynamicParams.put(SoMapperKey.HTIME,AdsManager.getInstance().getIsQRCodeVideoTime() + "");

        return reqParam;
    }

    /**
     * 直播播放器内广告，需要与正片相关的信息
     *
     * @return
     */
    public static ArkAdReqParam getLivePlayerInfo(Context context, String streamUrl, String uuid, String uid, String ty, IPlayerStatusDelegate iPlayerStatusDelegate) {
        ArkAdReqParam reqParam = getClientInfo(context);
        reqParam.adReqType = ArkAdReqParam.AdReqType.REQ_Live;
        if (reqParam.dynamicParams == null){
            reqParam.dynamicParams = new HashMap<String, String>();
        }
        reqParam.dynamicParams.put(SoMapperKey.STREAM_URL,streamUrl);
        reqParam.iPlayerStatusDelegate = iPlayerStatusDelegate;
        reqParam.dynamicParams.put(SoMapperKey.PY, "");
        reqParam.dynamicParams.put(SoMapperKey.UID, uid);
        reqParam.dynamicParams.put(SoMapperKey.UUID, uuid);// 播放器生成的，用户一次播放视频的唯一标识
        reqParam.dynamicParams.put(SoMapperKey.TY, ty);

        return reqParam;
    }
}
